package com.thinker.loan.consumer.service.processor;

import com.thinker.loan.consumer.enumeration.LoanStatus;
import com.thinker.loan.consumer.model.LoanApplicationRequest;
import com.thinker.loan.consumer.service.OcrService;
import com.thinker.loan.consumer.service.WatchlistService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class KycProcessor extends AbstractLoanProcessor {
    private final OcrService ocrService;
    private final WatchlistService watchlistService;

    @Override
    public void process(LoanApplicationRequest request) {
        if (!ocrService.validateIdCard(request.getCustomer().getIdCard())) {
            request.setStatus(LoanStatus.REJECTED);
            request.setRejectReason("KYC验证失败");
            return;
        }

        if (watchlistService.checkWatchlist(request.getCustomer().getIdCard())) {
            request.setStatus(LoanStatus.REJECTED);
            request.setRejectReason("命中监控名单");
            request.setWatchlistFlag(true);
            return;
        }

        request.setStatus(LoanStatus.KYC_PASSED);
    }
}
